package daybook.model;

import daybook.annotation.Bean;
import org.immutables.value.Value;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

@Bean
@Value.Immutable
public abstract class Book {
    private static final Logger LOG = LoggerFactory.getLogger(Book.class);
    public static final String DEFAULT_ACCOUNT_NAME_SEPARATOR = "|";

    public abstract ChartOfAccounts getChartOfAccounts();
    public abstract Commodity getDefaultCurrency();
    public abstract Map<String, Commodity> getCommodities();

    @Value.Default
    public String getAccountNameSeparator() {
        return DEFAULT_ACCOUNT_NAME_SEPARATOR;
    }

    private static final String ACCOUNT_NAME_SEPARATORS = "|:/\\#";
    public static boolean isValidAccountNameSeparator(String accountNameSeparator) {
        return accountNameSeparator.length() == 1 &&
                ACCOUNT_NAME_SEPARATORS.contains(accountNameSeparator);
    }
}
